// xc/components/footnav.js
Component({
  /**
   * 组件的属性列表
   */
  options: {
    addGlobalClass: true,
    multipleSlots: true
  },
  properties: {

    keyval: {
      type: [ String],
      default: true
    },
    bottomnav: {
      type: Object,
      default: {}
    },
  },

  ready(){
    var that= this
    var app=getApp();
    var keyval = this.data.keyval


   if(app.globalData.footnav[keyval]){
    this.setnavdata(app.globalData.footnav[keyval]);
   } 
   else
   {
    
    app.xc_sys_config.loadfootnav(keyval).then(res=>{
       if(res["status"]==1){        
        that.setnavdata(app.globalData.footnav[keyval]);
       }

      return 
    
 
    })
 
   }

   

  },
  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    callphone(e) {
      wx.makePhoneCall({
        phoneNumber: e.currentTarget.dataset.phone
      })
    },
    h5link(e){
      var $_pages = getCurrentPages();
      let that = $_pages[$_pages.length - 1];
    var $xcmodel= that.__route__.split('/')[0];
      wx.navigateTo({
        url: '/xc_demoone/pages/web/index?url=' + e.currentTarget.dataset.url ,
      })
     
    },    
    setnavdata(navdata) {      
      var $_pages = getCurrentPages();
      var plen = $_pages.length;
      if (plen < 1) {
        return;
      }
      let that = $_pages[plen - 1]; 
      if (navdata)
      {
        let tabBar =navdata;             
        for (let i in tabBar['list']) {
          if (tabBar['list'][i]['url'] && tabBar['list'][i]["cid"]==1)
          {
            tabBar['list'][i]['url'] = tabBar['list'][i]['url'].replace(/(\?|#)[^"]*/g, '')
          }         
        }
        this.setData({
          tabBar: tabBar,
          'tabBar.thisurl': that.__route__,
          // cartnum: cartnum
        })
      }       
    },     
      islogin(e){
        var that = this;        
        var userreg = this.selectComponent("#userreg");
        if(userreg.islogin()) {
    

          wx.redirectTo({
            url: e.currentTarget.dataset.url,
          })
        }   
      }
  }
})
